package com.xm.redis.zset;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * Lettuce：基于 Netty，支持异步和非阻塞 I/O，适合高并发场景
 * Jedis：直连模式，简单轻易，但并发性能略逊于 Lettuce
 */
@Service
public class RankingService {

    @Autowired
    private ZSetOperations<String, Object> zSetOps;

    public void addToRank(String key, Object number, double score) {
        zSetOps.add(key, number, score);
    }

    public Set<Object> getTop3(String key) {
        return zSetOps.reverseRange(key, 0, 2);
    }
}
